import request from '@/utils/request'

import _request from '@/services/baseService'

function getToken() {
  const token = localStorage.getItem('business-token')
  return token
}

// 查询所有订单
export async function queryOpeOrderByCondition(params) {
  return request(`/hzsx/business/order/queryOrderByCondition`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询所有订单状态统计
export async function queryOrderGroupCountByCondition(params) {
  return request(`/hzsx/business/order/queryOrderGroupCountByCondition`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询所有订单带详情
export async function queryOrderByConditionExt(params) {
  return request(`/hzsx/business/order/queryOrderByConditionExt`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

export async function purchaseOrderExport(params) {
  return request(`/hzsx/purchaseOrder/export`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

export async function userOrdersPurchase(params) {
  return request(`/hzsx/purchaseOrder/detail?orderId=${params.orderId}`, {
    method: 'get',
    data: params,
    headers: { token: getToken() }
  })
}

export async function userOrderPurchase(params) {
  return request(`/hzsx/purchaseOrder/page`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询关闭订单
export async function queryPendingOrderClosureList(params) {
  return request('/hzsx/business/order/queryPendingOrderClosureList', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

export const applyCancel = data =>
  request(
    `/hzsx/business/order/applicationCancellation?orderId=${data.orderId}&status=${data.status}`,
    {
      method: 'POST', // data,
      headers: { token: getToken() }
    }
  )

// 关闭订单并退款
export async function closeUserOrderAndRefundPrice(params) {
  return request('/hzsx/business/order/closeUserOrderAndRefundPrice', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 获取各状态订单数量
export async function businessOrderStatisticsUsing(params) {
  return request('/hzsx/business/order/businessOrderStatistics', {
    method: 'POST',
    body: params,
    headers: { token: getToken() }
  })
}

// 查询逾期订单列表
export async function queryOpeOverDueOrdersByCondition(params) {
  return request('/hzsx/business/order/queryOverDueOrdersByCondition', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询即将到期订单列表
export async function queryOpeGoingOverDueOrdersByCondition(params) {
  return request('/hzsx/business/order/queryOpeGoingOverDueOrdersByCondition', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 待归还订单列表
export async function queryWaitingGiveBackOrder(params) {
  return request('/hzsx/business/order/queryWaitingGiveBackOrder', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询电审订单
export async function queryTelephoneAuditOrder(params) {
  return request('/hzsx/business/order/queryTelephoneAuditOrder', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 电审审核
export async function telephoneAuditOrder(params) {
  return request('/hzsx/business/order/telephoneAuditOrder', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询运营买断订单
export async function queryOpeBuyOutOrdersByCondition(params) {
  return request('/hzsx/business/order/queryBuyOutOrdersByCondition', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询续租订单
export async function queryReletOrderByCondition(params) {
  return request('/hzsx/business/order/queryReletOrderByCondition', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 获取上架渠道集合
export async function PlateformChannel(params) {
  return request('/hzsx/platform/selectPlateformChannel', {
    method: 'GET',
    data: params,
    headers: { token: getToken() }
  })
}

// 订单备注
export async function orderRemark(params) {
  return request('/hzsx/business/order/orderRemark', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
export async function saveOrUpdateOrderCustomerAttendance(params) {
  return request('/hzsx/dataViewCount/saveOrUpdateOrderCustomerAttendance', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
export async function purchaseOrder(params) {
  return request('/hzsx/purchaseOrder/cancel', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

export async function queryUserWeixinPage(params) {
  return request('/hzsx/weixin/queryUserWeixinPage', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询订单账单相关信息
export async function queryOrderStagesDetail(params) {
  return request('/hzsx/business/order/queryOrderStagesDetail', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 查询订单商品信息变更相关信息
export async function selectProductByProducetId(productId) {
  return request(`/hzsx/product/selectProductByProducetId?productId=${productId.productId}`, {
    method: 'GET',
    headers: { token: getToken() }
  })
}
// 修改订单商品信息变更相关信息
export async function changeProductForOrder(params) {
  return request('/hzsx/business/order/changeProductForOrder', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
export async function modifyUserWeixin(params) {
  return request('/hzsx/weixin/modifyUserWeixin', {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

export async function deleteUserWeixin(params) {
  return request(`/hzsx/weixin/deleteUserWeixin?id=${params.id}`, {
    method: 'get',

    headers: { token: getToken() }
  })
}

export async function saveWeixinUserInfo(params) {
  return request(
    `/hzsx/weixin/saveWeixinUserInfo?code=${params.code}&state=${params.state}`,
    {
      method: 'get' // headers: { token: getToken() },
    }
  )
}

// 查询订单详细
export async function queryOpeUserOrderDetail(params) {
  return request(`/hzsx/business/order/queryBusinessUserOrderDetail`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询备注
export async function queryOrderRemark(params) {
  return request(`/hzsx/business/order/queryOrderRemark`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 订单导出
export async function exportOpeAllUserOrders(params) {
  return request(`/hzsx/business/order/exportOpeAllUserOrders`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 订单导出---new
export async function exportQueryOrderByConditionExt(params) {
  return request(`/hzsx/business/order/exportQueryOrderByConditionExt`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 买断订单导出

export async function exportOpeBuyOutUserOrders(params) {
  return request(`/hzsx/business/order/exportOpeBuyOutUserOrders`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 逾期订单导出
export async function exportOpeOverDueUserOrders(params) {
  return request(`/hzsx/business/order/excelOverDueOrdersByCondition`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() },
    responseType: 'blob'
  })
}

// 到期未归还订单导出
export async function exportWaitingGiveBack(params) {
  return request(`/hzsx/business/order/exportWaitingGiveBack`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 续租订单导出
export async function exportReletOrders(params) {
  return request(`/hzsx/business/order/exportReletOrders`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 电审订单导出
export async function exportTelephoneAuditOrders(params) {
  return request(`/hzsx/business/order/exportTelephoneAuditOrders`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 订单关闭和退款导出
export async function exportCloseRefundOrders(params) {
  return request(`/hzsx/business/order/exportCloseRefundOrders`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询物流信息
export async function queryExpressInfo(params) {
  return request(
    `/hzsx/business/order/queryExpressInfo?expressNo=${params.expressNo}&receiverPhone=${params.receiverPhone}&shortName=${params.shortName}`,
    {
      method: 'GET',
      headers: { token: getToken() }
    }
  )
}

export async function contractReport(params) {
  return request(`/hzsx/business/order/contractReport`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询运营买断订单详情
export async function queryOpeBuyOutOrderDetail(params) {
  return request(`/hzsx/business/order/queryBuyOutOrderDetail`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询续租订单详情
export async function queryUserReletOrderDetail(params) {
  return request(`/hzsx/business/order/queryUserReletOrderDetail`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 补打印（重新打印）按钮
export async function sfRepeatPrintExpress(params) {
  return request(`/hzsx/business/order/sfRepeatPrintExpress`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 后台获取区域信息
export async function selectDistrict(params) {
  return request('/hzsx/district/selectDistrict', {
    method: 'GET',
    headers: { token: getToken() }
  })
}

// 修改用户收货地址
export async function opeOrderAddressModify(params) {
  return request(`/hzsx/business/order/opeOrderAddressModify`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

export async function getSiriusReportRecord(params) {
  return request(`/hzsx/business/order/querySiriusReportByUid`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

export async function getSiriusReportRecordV3(params) {
  return request(`/hzsx/business/order/querySiriusReportByUidV3`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

export async function purchaseOrderDelivery(params) {
  return request(`/hzsx/purchaseOrder/delivery`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 查询蚂蚁链信息
export async function getChainInfoByOrderId(params) {
  return request(
    `/hzsx/business/order/getChainInfoByOrderId?orderId=${params.orderId}`,
    {
      method: 'GET',
      headers: { token: getToken() }
    }
  )
}

// 查询蚁盾分
export async function getUserRisk(params) {
  return request(`/hzsx/business/order/getUserRisk?orderId=${params.orderId}`, {
    method: 'GET',
    headers: { token: getToken() }
  })
}

// 手动扣除分期账单
export async function orderByStagesPay(params) {
  return request(`//${location.hostname}/api-web/hzsx/api/orderByStages/userOrderActiveWithhold`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 手动扣除分期账单
export async function paidPeriodOrder(params) {
  return request(`/hzsx/business/order/billPay`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 增值服务--碎屏险--代扣
export async function orderServicePay(params) {
  return request(`/hzsx/business/order/orderServicePay`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 增值服务--碎屏险--退款
export async function orderServiceRefund(params) {
  return request(`/hzsx/business/order/orderServiceRefund`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 订单账单信息分期信息修改价格
export async function updateOrderStagesById(params) {
  return request(`/hzsx/business/order/updateOrderStagesById`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 订单账单信息修改增值服务价格
export async function updatePriceByOrderAdditionalServicesId(params) {
  return request(`/hzsx/dataViewCount/updatePriceByOrderAdditionalServicesId`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 手动扣除分期账单--状态变成已支付，添加线下退款按钮
export async function billRefundOrder(params) {
  return request(`/hzsx/business/order/billRefund`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}
// 待归还状态下手动关闭订单
export async function finishedOrder(params) {
  return request(`/hzsx/business/order/businessFinishedOrder`, {
    method: 'POST',
    data: params,
    headers: { token: getToken() }
  })
}

// 修改订单押金
export async function modifyOrderDeposit(params) {
  return request(
    `/hzsx/business/order/updateOrderDeposit?orderId=${params.orderId}&freezePrice=${params.freezePrice}`,
    {
      method: 'POST', // data: params,
      headers: { token: getToken() }
    }
  )
}

// 抢单大厅订单列表
export async function rushOrderCenter(data) {
  return request(`/hzsx/business/order/rushOrderCenter`,
    {
      method: 'POST', 
      data: data,
      headers: { token: getToken() }
    }
  )
}


// 捞单大厅订单列表
export async function rejectOrderCenter(data) {
  return request(`/hzsx/business/order/rejectOrderCenter`,
    {
      method: 'POST', 
      data: data,
      headers: { token: getToken() }
    }
  )
}

// 我的订单
export async function rentOrderPageList(data) {
  return request(`/hzsx/order/rentOrders/rentOrderPageList`,
    {
      method: 'POST', 
      data: data,
      headers: { token: getToken() }
    }
  )
}



/**
 * 关联订单
 * "originalOrderNo": "", 订单id
 * "orderSource":  "",  订单模式：01-平台分派 02-抢单中心 03-捞单中心
**/
export async function addRentOrder(data) {
  return request(`/hzsx/order/rentOrders/addRentOrder`,
    {
      method: 'POST', 
      data: data,
      headers: { token: getToken() }
    }
  )
}




export default {
  orderDelivery: data => {
    return _request(`/hzsx/business/order/orderDelivery`, data)
  },
  merchantsIssuedStatements: data => {
    return _request(`/hzsx/business/order/merchantsIssuedStatements`, data)
  },
  selectExpressList: data => {
    return _request(`/hzsx/platformExpress/selectExpressList`, data, 'get')
  },
  //创建免单好
  createExpressNo: data => {
    return _request(`/hzsx/business/order/sfPrintExpress`, data, 'post')
  },
  //退租关单更换接口
  businessClosePayedOrder: data => {
    return _request(`/hzsx/business/order/close`, data)
  }, // 未支付订单关闭
  businessCloseUnPayOrder: data => {
    return _request(`/hzsx/business/order/businessCloseUnPayOrder`, data)
  },
  queryOrderStatusTransfer: data => {
    return _request(`/hzsx/business/order/queryOrderStatusTransfer`, data)
  },
  queryOrderAuditRecord: data => {
    return _request(`/hzsx/business/order/queryOrderAuditRecord`, data)
  },
  telephoneAuditOrder: data => {
    return _request(`/hzsx/business/order/telephoneAuditOrder`, data)
  },
  orderHasten: data => {
    return _request(`/hzsx/ope/order/orderHasten`, data)
  },
  queryOrderHasten: data => {
    return _request(`/hzsx/ope/order/queryOrderHasten`, data)
  },
  modifyOverdueFee: data => {
    return _request(`/hzsx/business/order/modifyBusinessOverdueFee`, data)
  },
  signReject: data => {
    return _request(`/hzsx/business/order/chgzContract/refuse`, data)
  },
  signPass: data => {
    return _request(`/hzsx/business/order/chgzContract/submitSignFile`, data)
  },
  // 获取合同地址
  getSignDownloadUrl: data =>{
    return request(`//${location.hostname}/api-web/hzsx/api/order/esign/signFlowFileDownloadUrl?flowId=${data.flowId}`, {
      method: 'GET'
    })
  },
}
// 前置风控结果
export async function userPreRiskCheck(params) {
  return request(`/hzsx/userOrders/userOrderBankPreRiskCheck`, {
    method: 'GET',
    data: params,
    headers: { token: getToken() }
  })
}
